import numpy as np
from path import Path
import sys
class Graph(object):
    def __init__(self):
        with open("adjMatrix.txt",encoding = 'utf-8') as f:
            self.adj = np.loadtxt("adjMatrix.txt", int,delimiter = " ")
            self.n = len(self.adj)
    def path_len(self, path):
        l = 0# the length of path
        n = len(path) # the number of nodes in path
        for i in range(n-1):
            l += self.adj[path[i]][path[i+1]]
            #print("(",path[i],",",path[i+1],")")
            #print(self.adj[i][i+1])
        return l


G = Graph()
n = G.n
P = Path(n)
'''
path = P.generate()
print(G.adj)
print(path)
print(G.path_len(path))
'''


print("***********start************")
mlen = sys.maxsize
mpath = []
with open("permutation.txt",encoding = "utf-8") as f:
    paths = np.loadtxt("permutation.txt", int, delimiter = " ")
    for path in paths:
        if G.path_len(path) < mlen:
            mlen = G.path_len(path)
            mpath = path
print("the number of nodes:",G.n)
print(G.adj)
print(mlen)
print(mpath)

print("************end**************")


